#import "LeftViewController.h"
#import "SMViewController.h"
#import "SettingsViewController.h"
#import "TeacherCenterViewController.h"
#import "TeacherViewController.h"
#import "MyClassViewController.h"
#import "GalleryViewController.h"
#import "ClassCameraViewController.h"
#import "UserInfo.h"
#import "UserDao.h"
#import "ImageUtil.h"
#import "AppDelegate.h"
#import "UIImageView+WebCache.h"
#import "UIViewExt.h"

@interface LeftViewController ()

@property (nonatomic, weak) IBOutlet UIImageView *backView;
@property (nonatomic, retain) UIImageView *headView;
@property (nonatomic, retain) UILabel *nickname;

@end

@implementation LeftViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    _backView.userInteractionEnabled = YES;
    
    _headView = [[UIImageView alloc] initWithFrame:CGRectMake((APP_SCREEN_WIDTH - 60 - 74) / 2, 46, 74, 74)];
    _headView.backgroundColor = [UIColor clearColor];
    _headView.layer.cornerRadius = 37.0f;
    _headView.layer.masksToBounds = YES;
    _headView.userInteractionEnabled = YES;
    [_backView addSubview:_headView];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(userInfoCallback:)];
    [_headView addGestureRecognizer:tap];
    
    _nickname = [[UILabel alloc] initWithFrame:CGRectMake(0, _headView.bottom + 13, APP_SCREEN_WIDTH - 60, 17)];
    _nickname.backgroundColor = [UIColor clearColor];
    _nickname.textAlignment = NSTextAlignmentCenter;
    _nickname.font = [UIFont systemFontOfSize:17.0f];
    _nickname.textColor = [UIColor whiteColor];
    [_backView addSubview:_nickname];
    
    UIImageView *gIcon = [[UIImageView alloc] initWithFrame:CGRectMake(40, _nickname.bottom + 42, 24, 24)];
    gIcon.backgroundColor = [UIColor clearColor];
    gIcon.image = [UIImage imageNamed:@"left_btn_gallery"];
    [_backView addSubview:gIcon];
    
    UILabel *gallery = [[UILabel alloc] initWithFrame:CGRectMake(gIcon.right + 10, gIcon.top, 120, 24)];
    gallery.backgroundColor = [UIColor clearColor];
    gallery.font = [UIFont systemFontOfSize:17.0f];
    gallery.userInteractionEnabled = YES;
    gallery.textColor = [UIColor whiteColor];
    gallery.text = @"宝贝作品秀";
    [_backView addSubview:gallery];
    UITapGestureRecognizer *galleryTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(galleryButtonCallback:)];
    [gallery addGestureRecognizer:galleryTap];
    
    UIImageView *cIcon = [[UIImageView alloc] initWithFrame:CGRectMake(gIcon.left, gIcon.bottom + 30, 24, 24)];
    cIcon.backgroundColor = [UIColor clearColor];
    cIcon.image = [UIImage imageNamed:@"left_btn_camera"];
    //[_backView addSubview:cIcon];
    
    UILabel *camera = [[UILabel alloc] initWithFrame:CGRectMake(cIcon.right + 10, cIcon.top, 120, 24)];
    camera.backgroundColor = [UIColor clearColor];
    camera.font = [UIFont systemFontOfSize:17.0f];
    camera.userInteractionEnabled = YES;
    camera.textColor = [UIColor whiteColor];
    camera.text = @"班级摄像头";
    //[_backView addSubview:camera];
    UITapGestureRecognizer *cameraTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(classCameraCallback:)];
    [camera addGestureRecognizer:cameraTap];
    
    UIImageView *sIcon = [[UIImageView alloc] initWithFrame:CGRectMake(gIcon.left, APP_SCREEN_HEIGHT - 30 - 24, 24, 24)];
    sIcon.backgroundColor = [UIColor clearColor];
    sIcon.image = [UIImage imageNamed:@"left_btn_setting"];
    [_backView addSubview:sIcon];
    
    UILabel *setting = [[UILabel alloc] initWithFrame:CGRectMake(sIcon.right + 10, sIcon.top, 120, 24)];
    setting.backgroundColor = [UIColor clearColor];
    setting.font = [UIFont systemFontOfSize:17.0f];
    setting.userInteractionEnabled = YES;
    setting.textColor = [UIColor whiteColor];
    setting.text = @"系统设置";
    [_backView addSubview:setting];
    UITapGestureRecognizer *settingTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(settingCallback:)];
    [setting addGestureRecognizer:settingTap];
    
    
}

- (void)viewDidAppear:(BOOL)animated {
    
    [_headView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",AVATAR_HEADER,[[UserDao getInstance] getUserInfo].avatar]]placeholderImage:[UIImage imageNamed:@"default_circle_icon"]];
   
    _nickname.text = [[UserDao getInstance] getUserInfo].nickName;
    
    AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    if (delegate) {
        [delegate checkSplashView];
        if (![[UserDao getInstance] getUserInfo].hasLogin) {
           
        }
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)userInfoCallback:(id)sender {
    
    TeacherViewController *teacherViewController = [[TeacherViewController alloc] init];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:teacherViewController];
    [[SMViewController sharedSMViewController]presentViewController:nav animated:YES completion:nil];
   // [self showViewController:nav sender:nil];
}

- (void)galleryButtonCallback:(id)sender {

    GalleryViewController *gallery = [[GalleryViewController alloc] init];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:gallery];
    [[SMViewController sharedSMViewController]presentViewController:nav animated:YES completion:nil];
}

- (void)classCameraCallback:(id)sender {
    
    ClassCameraViewController *classCameraViewController = [[ClassCameraViewController alloc] init];
    [[SMViewController sharedSMViewController]presentViewController:classCameraViewController animated:YES completion:nil];
    NSLog(@"Click My class Camera.");
}

- (void)settingCallback:(id)sender {

    SettingsViewController *settingsViewController = [[SettingsViewController alloc] init];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:settingsViewController];
   [[SMViewController sharedSMViewController]presentViewController:nav animated:YES completion:nil];
    NSLog(@"Click setting.");
}

@end
